unit cx_timer;

interface

uses
 Windows;

type
 TTimerCallBack = procedure (hWnd: HWND; Message: Word; TimerID: Word; SysTime: LongInt); stdcall;

var
 TimerProc: TTimerCallBack = nil;

procedure ResetTimer;
procedure CloseTimer;

implementation

uses
 m_globaldefs, m_api, dbsettings,
 cx_vars;

var
 cx_UpdateTimer: Integer = 0;

procedure CloseTimer;
begin
 if cx_UpdateTimer>0 then
  begin
   KillTimer(0, cx_UpdateTimer);
   cx_UpdateTimer:=0;
  end;
end;

procedure ResetTimer;
 var
  interval: Integer;
begin
 if DBGetSettingType(0, piShortName, cx_opt_RefreshInterval)=DBVT_DWORD then
   interval:=DBGetContactSettingDWord(0, piShortName, cx_opt_RefreshInterval, IntervalDefault)
 else
  begin
   interval:=IntervalDefault;
   DBWriteContactSettingDWord(0, piShortName, cx_opt_RefreshInterval, interval);
  end;
 CloseTimer;
 cx_UpdateTimer := SetTimer(0, 1, interval*1000, @TimerProc);
end;

end.
